//
//  GLTextureShader.m
//  LMPhotoVideoSDK
//
//  Created by Aimar on 16/7/6.
//  Copyright © 2016年 魁钺会. All rights reserved.
//

#import "GLTextureShader.h"



@interface GLTextureShader () {
    GLint      _texCoordHandle;
    GLint      _samplerHandle;
}

@end

@implementation GLTextureShader

- (BOOL)onProgramCreate {
    if (![super onProgramCreate]) {
        return NO;
    }
    
    _texCoordHandle = glGetAttribLocation(self.programId, "texCoord");
    _samplerHandle = glGetUniformLocation(self.programId, "sampler");
//
    glActiveTexture(GL_TEXTURE0);
    glUniform1i(_samplerHandle, 0);
//
    return YES;
}

- (void)onProgramBind {
    [super onProgramBind];
    
    glEnableVertexAttribArray(_texCoordHandle);
}

- (void)setTextureCoord:(GLfloat*)coords component:(GLint)component {
    glVertexAttribPointer(_texCoordHandle, component, GL_FLOAT, GL_FALSE, component * sizeof(GLfloat), coords);
}

@end
